/**
 * Created by jade on 2014-12-09.
 */

//## 지역 이름 콤보
var fnComboZone = function(expressCd, target) {

    var param  = "expressCd="+expressCd;
    var valUrl = "./action/common/listZone.php";

    $.ajax({
        url: valUrl,
        type: 'POST',
        dataType: 'json',
        data: param,
        success: function(data){
            $('#'+target).html('');
            var options = '<option value="">=지역=</option>';
            for (k=0; k<data.TBLZONECD.length; k++)
            {
                var comboData = data.TBLZONECD[k];
                options += '<option value="'+comboData.ZONECD+'">'+comboData.ZONENM+'</option>';
            }
            $('#'+target).append(options);
        },
        error: function(data){
            alert('Error!!');
            alert(data.responseText);
        }
    });
}

//## Express 업체 콤보
var fnComboExpress = function(expressCd, target) {

    var param  = "expressCd="+expressCd;
    var valUrl = "./action/common/listExpress.php";

    $.ajax({
        url: valUrl,
        type: 'POST',
        dataType: 'json',
        data: param,
        success: function(data){
            $('#'+target).html('');
            var options = '<option value="">=Express=</option>';
            for (k=0; k<data.TBLCOMCODE.length; k++)
            {
                var comboData = data.TBLCOMCODE[k];
                if (expressCd == comboData.ITEMCD) var chk = ' selected="selected"';
                else var chk = '"';
                options += '<option value="'+comboData.ITEMCD+'"'+chk+'>'+comboData.ITEMNM+'</option>';
            }
            $('#'+target).append(options);
        },
        error: function(data){
            alert('Error!!');
            alert(data.responseText);
        }
    });
}


//## Express Item Type 콤보
var fnComboExpressType = function(target) {

    var param  = "";
    var valUrl = "./action/common/listExpressType.php";

    $.ajax({
        url: valUrl,
        type: 'POST',
        dataType: 'json',
        data: param,
        success: function(data){
            $('#'+target).html('');
            var options = '<option value="">=Type=</option>';
            for (k=0; k<data.TBLCOMCODE.length; k++)
            {
                var comboData = data.TBLCOMCODE[k];
                if (expressCd == comboData.ITEMCD) var chk = ' selected="selected"';
                else var chk = '"';
                options += '<option value="'+comboData.ITEMCD+'"'+chk+'>'+comboData.ITEMNM+'</option>';
            }
            $('#'+target).append(options);
        },
        error: function(data){
            alert('Error!!');
            alert(data.responseText);
        }
    });
}


//## 거래처 콤보
var fnComboCompany = function(company, compCd, target, m) {

    if(m == undefined) {
        if (event.keyCode != "13") {
            return; // 엔터일때만 수행
        }
    }

    var param  = "findCompany="+company;
    param  += "&compCd="+compCd;
    var valUrl = "./action/common/listCompany.php";

    $.ajax({
        url: valUrl,
        type: 'POST',
        dataType: 'json',
        data: param,
        success: function(data){
            $('#'+target).html('');
            var options = '<option value="">=거래처=</option>';
            if (data.TOTAL_COUNT > 0) {
                for (k = 0; k < data.TBLCOMPANY.length; k++) {
                    var comboData = data.TBLCOMPANY[k];
                    if (compCd == comboData.COMPCD) var chk = ' selected="selected"';
                    else var chk = '"';
                    options += '<option value="' + comboData.COMPCD + '"' + chk + '>' + decodeURIComponent(comboData.COMPANYKR) + '</option>';
                }
                $('#' + target).append(options);
            }
        },
        error: function(data){
            alert('Error!!');
            alert(data.responseText);
        }
    });
}
